package br.com.invest.action;

import br.com.invest.model.Cotacao;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

/**
 *
 * @author Kirmaier
 */
@Name("CotacaoController")
@Scope(ScopeType.SESSION)
public class CotacaoController {

    private List<Cotacao> listaCotacoes;
    private SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    @In
    private Session investDB;

    //@Factory("cotacaoDM")
    public List<Cotacao> exibirCotacoes() {

        Calendar calendario = new GregorianCalendar();
        Date data = new Date();
        calendario.setTime(data);

        List<Cotacao> lc = investDB.createCriteria(Cotacao.class)        
                .add(Restrictions.eq("dataCotacao", calendario.getTime()))
                .createAlias("acao", "acao")
                .addOrder(Order.asc("acao.nome"))
                .list();

        listaCotacoes = new ArrayList<Cotacao>();
        for (Cotacao c : lc) {
            listaCotacoes.add(c);
        }
        return listaCotacoes;
    }

    //<editor-fold defaultstate="collapsed" desc="Getters e Setters">;
    public List<Cotacao> getListaCotacoes() {
        return listaCotacoes;
    }

    public void setListaCotacoes(List<Cotacao> listaCotacoes) {
        this.listaCotacoes = listaCotacoes;
    }
    //</editor-fold>
}
